package cn.nai.DemoRan.demo09;
import java.util.*;
//利用所学的集合知识，完成从键盘上接收一段英文句子，统计出其中的各个字符的个数，并找出出现次数最多的那个字符。
public class Eng_count {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        int counter = 0;
        str1 = str1.toUpperCase().replaceAll("[^(a-zA-Z)]"," ");
        String str3[] = str1.split("\\b");
        //记录单词
        Map<String , Integer> map = new HashMap<String , Integer>();
        //统计各个单词出现的次数
        for (String s1 : str3)
        {
            //将字符串俩端的空格去掉
            if(s1.trim().length()>0){
                s1=s1.trim();
                int count = str1.split("\\b"+s1.trim()+"\\b").length-1;
                map.put(s1, count);
            }else{
                map.put("空格", counter++);
            }
        }

        System.out.println("\n单词出现的次数分别为：");
        //单词出现次数
        int a = 0;
        String b = "";
        for (String key : map.keySet()) {
            if(map.get(key)>a){
                a = map.get(key);
                b = key;
            }
            System.out.println(key+"出现："+map.get(key)+"次");
        }
        System.out.println("\n出现次数最多的是："+b+"\n"+"出现了"+a+"次\n");




    }
}
